package myJs.tool

import myJs.Implicits._

import scala.scalajs.js
import scala.scalajs.js.|

/**
 * Created by yz on 20/1/2021
 */
class Messages(dict: JDS) {

  def apply(key: String) = {
    dict.apply(key)
  }

  def apply(key: String, args: String | Int*): String = {
    val r = "\\{(\\d+)\\}".r
    val str = dict.apply(key)
    val rs = r.replaceAllIn(str, replacer => {
      val index = (replacer.group(1)).toInt
      args(index).toString
    })
    rs
  }

  def getOrElse(key: String, default: String) = {
    dict.getOrElse(key, default)
  }

}
